//
//  SunFirstVC.m
//  Xspcf
//
//  Created by sunshine on 16/10/8.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "SunFirstVC.h"
#import "SDCycleScrollView.h"
#import "SunCycleProgress.h"
#import "SunWebVC.h"
#import "SunProductDetailVC.h"
#import "MJRefresh.h"
#import "JxWebVC.h"
#import "ColorButton.h"
#import "UIButton+WebCache.h"
#undef Y
#define Y(y) BY(y)
@interface SunFirstVC ()<SDCycleScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UIWebViewDelegate>
{
    SDCycleScrollView *_banner;
    SDCycleScrollView *_news;
    UILabel *_title;
    UIImageView *_state;
    UILabel *_stateTitle;
//    SunCycleProgress *_progress;
    UILabel *_percent;
    UIButton *_startBtn;//开始按钮
    UILabel *_day;//剩余天数
    UILabel *_limit;//起购金额
//    UILabel *_leave;//剩余金额
    UILabel *_safeLabel;
    UIView *_test;
    NSMutableArray *_bannerArr;
    NSMutableArray *_newsArr;
    NSMutableDictionary *_details;
    Sun *_sun;
    NSDictionary *_adsData;
    UITableView *_tb;
    UIWebView *_web;
    UIButton *_flaot;
    UIImageView *_helpView;
}

@property (nonatomic, strong) NSDictionary *homeDic;
@property (nonatomic, strong) UILabel *dayLabel;
@property (nonatomic, strong) UILabel *dealLabel;
@property (nonatomic, strong) UILabel *earLabel;
@property (nonatomic, strong) UILabel *progress;
@property (nonatomic, strong) NSMutableArray *iconsArr;
@property (nonatomic, strong) UIView *iconsView;
@property (nonatomic, strong) NSArray *infoArr;
@property (nonatomic, strong) UILabel *progressLable;

@property (nonatomic, strong) NSArray *defaultIconArray;
@property (nonatomic, strong) NSDictionary *floatDic;

@end

@implementation SunFirstVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"F9F9F9"];
    [self initData];
    [self creatUI];
    [_sun showActivity:self];
    self.defaultIconArray = @[@{@"title":@"年度数据",@"image":@"first_defaulticon3",@"next":@"topic/operation_report"},@{@"title":@"邀请有礼",@"image":@"first_defaulticon4",@"next":@"topic/april_share"},@{@"title":@"安全保障",@"image":@"first_defaulticon1",@"next":@"guide_about.html"},@{@"title":@"运营数据",@"image":@"first_defaulticon2",@"next":@"topic/annual_report"}];
    
    if ([[Sun getUser:NOALERT] intValue] == 1) {
        [Sun setUser:@"0" forKey:NOALERT];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kIsOpen];
        return;
    }
    if (![[NSUserDefaults standardUserDefaults] boolForKey:kIsOpen]) {
        [self showRegister];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kIsOpen];
    }else {
        [self requestToVersion];    // 更新提示

    }
    if (@available(iOS 11.0, *)) {
        _tb.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        //以下是tableview高度计算出现问题
        _tb.estimatedRowHeight = 0;
        _tb.estimatedSectionHeaderHeight=0;
        _tb.estimatedSectionFooterHeight=0;
        
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    [self requestURL];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}


- (void)viewWillDisappear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}


- (void)initData{
    _sun = [[Sun alloc]init];
}
- (UIButton *)btnWithImg:(UIImage *)img Title:(NSString *)title{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:img forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:@"535353"] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [btn verticalImageAndTitle:X(35)];
    return btn;
}
- (UIButton *)btnWithUrl:(NSString *)url Title:(NSString *)title{
    UIButton *btn = [[UIButton alloc]init];
    UIImageView *btnImage = [[UIImageView alloc]init];
    [btn addSubview: btnImage];
    [btnImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,url]]];
    [btnImage lt_setSize:CGSizeMake(X(22), X(22)) save:YES];
    [btnImage lt_XcenterTo:nil save:YES];
    [btnImage lt_setTop:X(18) to:nil save:YES];
//    [btn sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,url]] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:@"535353"] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [btn verticalImageAndTitle:X(35)];
    return btn;
}
#pragma mark- icons
- (void)setUpIconCell:(UITableViewCell *)cell{
    if (self.iconsArr.count == 0|| self.iconsArr == NULL) {
        // title image next
        for (int i=0; i<self.defaultIconArray.count; i++) {
            UIButton *iconBtn = [self btnWithImg:[UIImage imageNamed:[self.defaultIconArray[i] objectForKey:@"image"]] Title:[self.defaultIconArray[i] objectForKey:@"title"]];
            [cell addSubview:iconBtn];
            iconBtn.tag = 100 + i;
            [iconBtn setFrame:CGRectMake(SCREENWIDTH/4 * (i%4), i/4*X(74), SCREENWIDTH/4, X(74))];
            [iconBtn addTarget:self action:@selector(iconBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        }
    }else{
        for (int i=0; i<self.iconsArr.count; i++) {
            UIButton *iconBtn = [self btnWithUrl:[self.iconsArr[i] objectForKey:@"image"] Title:[self.iconsArr[i] objectForKey:@"title"]];
            [cell addSubview:iconBtn];
            iconBtn.tag = 200 + i;
            [iconBtn setFrame:CGRectMake(SCREENWIDTH/4 * (i%4), i/4*X(74), SCREENWIDTH/4, X(74))];
            [iconBtn addTarget:self action:@selector(iconBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
}
- (void)iconBtnAction:(UIButton*)btn {    
    SunWebVC *vc = [[SunWebVC alloc]init];
    NSString *str = @"CZfSDQzsuDayjfzE";
    NSString *str1 =@"12345678";
    NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
    NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
    if (btn.tag>=200) {
        vc.urlStr = [NSString stringWithFormat:@"%@?source=ios&token_id=%@&sign=%@",[self.iconsArr[btn.tag-200] objectForKey:@"next"],token_id,md5Str];
    }else{
        vc.urlStr = [NSString stringWithFormat:@"%@/%@?source=ios&token_id=%@&sign=%@",KWAP,[self.defaultIconArray[btn.tag-100] objectForKey:@"next"],token_id,md5Str];

    }
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark- 平台资讯
- (void)setUpInforCell:(UITableViewCell *)cell{
    UILabel *infoWord = [[UILabel alloc]init];
    [cell addSubview:infoWord];
    [infoWord lt_setLeft:X(15) to:nil save:YES];
    [infoWord lt_setTop:X(9) to:nil save:YES];
    infoWord.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
    infoWord.textColor = COLOR_TITLE_MAIN;
    infoWord.text = @"平台资讯";
    
    UIButton *allBtn = [[UIButton alloc]init];
    [cell addSubview:allBtn];
    [allBtn lt_setSize:CGSizeMake(X(100), X(38)) save:YES];
    [allBtn lt_setRight:0 to:nil save:YES];
    [allBtn lt_setTop:0 to:nil save:YES];
    [allBtn setTitle:@"查看全部" forState:UIControlStateNormal];
    allBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    [allBtn setTitleColor:[UIColor colorWithHexString:@"999999"] forState:UIControlStateNormal];
    UIImageView *next = [[UIImageView alloc]init];
    [allBtn addSubview:next];
    [next setImage:[UIImage imageNamed:@"first_next"]];
    [next lt_setSize:CGSizeMake(5, 9) save:YES];
    [next lt_YcenterTo:nil save:YES];
    [next lt_setRight:X(15) to:nil save:YES];
    [allBtn addTarget:self action:@selector(moreInfoAction) forControlEvents:UIControlEventTouchUpInside];
    
    if (self.infoArr.count>=1) {
        NSDictionary *dic1 = self.infoArr[0];
        UIButton *infoBtn1 = [[UIButton alloc]init];
        [cell addSubview:infoBtn1];
        [infoBtn1 setFrame:CGRectMake(0, X(40), SCREENWIDTH, X(104))];
        [infoBtn1 addTarget:self action:@selector(info1Action) forControlEvents:UIControlEventTouchUpInside];
        UIImageView *line1 = [[UIImageView alloc]init];
        [cell addSubview:line1];
        [line1 setImage:[UIImage imageNamed:@"all_line"]];
        [line1 setFrame:CGRectMake(X(15), X(38), SCREENWIDTH- X(30), 2)];
        UILabel *title1 = [[UILabel alloc]init];
        [infoBtn1 addSubview:title1];
        [title1 setFrame:CGRectMake(X(15), X(15), X(209), X(20))];
        title1.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        title1.textColor = COLOR_TITLE_MAIN;
        title1.text = [dic1 objectForKey:@"name"];
        UILabel *content1 = [[UILabel alloc]init];
        [infoBtn1 addSubview:content1];
        [content1 setFrame:CGRectMake(X(15), X(40), X(204), X(17))];
        content1.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
        content1.textColor = COLOR_TITLE_MINOR;
        content1.text = [dic1 objectForKey:@"content"];
        UIImageView *infoImage1 = [[UIImageView alloc]init];
        [infoBtn1 addSubview:infoImage1];
        [infoImage1 setFrame:CGRectMake(SCREENWIDTH - X(15+112), X(15), X(112), X(80))];
        infoImage1.layer.cornerRadius = 5;
        infoImage1.layer.masksToBounds = YES;
        [infoImage1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[dic1 objectForKey:@"img"]]] placeholderImage:[UIImage imageNamed:@"first_info_default"]];
        UILabel *fromWord1 = [[UILabel alloc]init];
        [infoBtn1 addSubview:fromWord1];
        fromWord1.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
        fromWord1.textColor = COLOR_TITLE_MINOR;
        fromWord1.text = @"来源";
        [fromWord1 setFrame:CGRectMake(X(15), X(81), X(40), X(14))];
        UILabel *from1 = [[UILabel alloc]init];
        [infoBtn1 addSubview:from1];
        from1.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
        from1.textColor = COLOR_TITLE_MAIN;
        from1.text = [dic1 objectForKey:@"author"];
        [from1 setFrame:CGRectMake(X(40), X(81), X(40), X(14))];
        UILabel *time1 = [[UILabel alloc]init];
        [infoBtn1 addSubview:time1];
        time1.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
        time1.textColor = COLOR_TITLE_MINOR;
        time1.text = [[Sun timestamp:[[dic1 objectForKey:@"addtime"] intValue] ToTime:@"YYYY-MM-dd HH:mm:ss"] substringToIndex:10];
        [time1 setFrame:CGRectMake(X(161), X(81), X(80), X(14))];
        if (self.infoArr.count>=2) {
            NSDictionary *dic2 = self.infoArr[1];
            UIButton *infoBtn2 = [[UIButton alloc]init];
            [cell addSubview:infoBtn2];
            
            [infoBtn2 setFrame:CGRectMake(0, X(146), SCREENWIDTH, X(104))];
            [infoBtn2 addTarget:self action:@selector(info2Action) forControlEvents:UIControlEventTouchUpInside];
            UIImageView *line2 = [[UIImageView alloc]init];
            [cell addSubview:line2];
            [line2 setImage:[UIImage imageNamed:@"all_line"]];
            [line2 setFrame:CGRectMake(X(15), X(144), SCREENWIDTH- X(30), 2)];
            UILabel *title2 = [[UILabel alloc]init];
            [infoBtn2 addSubview:title2];
            [title2 setFrame:CGRectMake(X(15), X(15), X(209), X(20))];
            title2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            title2.textColor = COLOR_TITLE_MAIN;
            title2.text = [dic2 objectForKey:@"name"];
            UILabel *content2 = [[UILabel alloc]init];
            [infoBtn2 addSubview:content2];
            [content2 setFrame:CGRectMake(X(15), X(40), X(204), X(17))];
            content2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
            content2.textColor = COLOR_TITLE_MINOR;
            content2.text = [dic2 objectForKey:@"content"];
            UIImageView *infoImage2 = [[UIImageView alloc]init];
            [infoBtn2 addSubview:infoImage2];
            [infoImage2 setFrame:CGRectMake(SCREENWIDTH - X(15+112), X(15), X(112), X(80))];
            infoImage2.layer.cornerRadius = 5;
            infoImage2.layer.masksToBounds = YES;
            [infoImage2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[dic2 objectForKey:@"img"]]] placeholderImage:[UIImage imageNamed:@"first_info_default"]];
            UILabel *fromWord2 = [[UILabel alloc]init];
            [infoBtn2 addSubview:fromWord2];
            fromWord2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
            fromWord2.textColor = COLOR_TITLE_MINOR;
            fromWord2.text = @"来源";
            [fromWord2 setFrame:CGRectMake(X(15), X(81), X(40), X(14))];
            UILabel *from2 = [[UILabel alloc]init];
            [infoBtn2 addSubview:from2];
            from2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
            from2.textColor = COLOR_TITLE_MAIN;
            from2.text = [dic2 objectForKey:@"author"];
            [from2 setFrame:CGRectMake(X(40), X(81), X(40), X(14))];
            UILabel *time2 = [[UILabel alloc]init];
            [infoBtn2 addSubview:time2];
            time2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
            time2.textColor = COLOR_TITLE_MINOR;
            time2.text = [[Sun timestamp:[[dic2 objectForKey:@"addtime"] intValue] ToTime:@"YYYY-MM-dd HH:mm:ss"] substringToIndex:10];
            [time2 setFrame:CGRectMake(X(161), X(81), X(80), X(14))];
        }
    }
}
#pragma mark- 更多资讯
- (void)moreInfoAction {
    SunWebVC *vc = [[SunWebVC alloc]init];
    vc.urlStr = [NSString stringWithFormat:@"%@%@",KWAP,@"/More/getArticleByNid?nid=Information&type=1&source=ios"];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)info1Action {
    SunWebVC *vc = [[SunWebVC alloc]init];
    NSDictionary *dic1 = self.infoArr[0];
//https://m.xspcf.com/More/getArticleById?id=1126&source=ios
    vc.urlStr = [NSString stringWithFormat:@"%@/More/getArticleById?id=%@&source=ios",KWAP,[dic1 objectForKey:@"id"]];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)info2Action {
    SunWebVC *vc = [[SunWebVC alloc]init];
    NSDictionary *dic1 = self.infoArr[1];
    vc.urlStr = [NSString stringWithFormat:@"%@/More/getArticleById?id=%@&source=ios",KWAP,[dic1 objectForKey:@"id"]];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark- 推荐标
- (void)setUpProductCell:(UITableViewCell *)cell{
//    newsBg.backgroundColor = [UIColor colorWithHexString:@"F9F9F9"];

    cell.backgroundColor = [UIColor colorWithHexString:@"F9F9F9"];
    UIImageView *contentBg = [[UIImageView alloc]init];
    contentBg.userInteractionEnabled = YES;
    [contentBg setImage:[UIImage imageNamed:@"first_contentbg"]];
    contentBg.userInteractionEnabled = YES;
    [cell addSubview:contentBg];
    [contentBg setFrame:CGRectMake(0, -2, SCREENWIDTH, X(288))];
    // 标名
    _title = [[UILabel alloc]init];
    [contentBg addSubview:_title];
    _title.textColor = COLOR_TITLE_MAIN;
    _title.font = [UIFont fontWithName:@"PingFangSC-Medium" size:14];
    _title.text = @"正在连接网络，请稍候。。。";
    [_title lt_setLeft:X(14) to:nil save:YES];
    [_title lt_setHeight:20 save:YES];
    [_title lt_setTop:X(10) to:nil save:YES];
    _state = [[UIImageView alloc]init];
    _state.image = [UIImage imageNamed:@"state_sign"];
    [contentBg addSubview:_state];
    [_state lt_setSize:CGSizeMake(X(90), X(36)) save:YES];
    [_state lt_setTop:0 to:nil save:YES];
    [_state lt_setRight:X(15) to:nil save:YES];
    _stateTitle = [[UILabel alloc]init];
    _stateTitle.textColor = [UIColor whiteColor];
    _stateTitle.textAlignment = NSTextAlignmentCenter;
    _stateTitle.font = [UIFont fontWithName:@"PingFangSC-Medium" size:14];
    _stateTitle.text = @"新手新手";
    [_state addSubview:_stateTitle];
    [_stateTitle lt_All:SunEdgesMake(0, 0, 4, 0) save:YES];
    
    _percent = [[UILabel alloc]init];
    [contentBg addSubview:_percent];
    _percent.textColor = COLOR_MAIN;
    _percent.font = [UIFont fontWithName:@"DINAlternate-Bold" size:42];
    [_percent lt_setLeft:X(10) to:nil save:YES];
    [_percent lt_setTop:X(29) to:_title save:YES];
    
    UILabel *perLabel = [[UILabel alloc]init];
    [contentBg addSubview:perLabel];
    perLabel.text = @"预期年化利率";
    perLabel.font = [UIFont systemFontOfSize:12];
    perLabel.textColor = COLOR_TITLE_MINOR;
    [perLabel lt_setLeft:X(14) to:nil save:YES];
    [perLabel lt_setTop:X(10) to:_percent save:YES];
    _day = [[UILabel alloc]init];
    [contentBg addSubview:_day];
    _day.font = [UIFont fontWithName:@"DINAlternate-Bold" size:24];
    _day.textColor = COLOR_TITLE_MAIN;
    [_day lt_setLeft:X(20) to:_percent save:YES];
    [_day lt_setTop:X(45) to:_title save:YES];
    UILabel *redPoint1 = [[UILabel alloc]init];
    [contentBg addSubview:redPoint1];
    redPoint1.textColor = COLOR_TITLE_MINOR;
    redPoint1.text = @"锁定期限";
    redPoint1.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    [redPoint1 lt_leftEqual:_day save:YES];
    [redPoint1 lt_YcenterTo:perLabel save:YES];
    
    UILabel *redPoint2 = [[UILabel alloc]init];
    [contentBg addSubview:redPoint2];
    redPoint2.textColor = COLOR_TITLE_MINOR;
    redPoint2.text = @"起借金额";
    redPoint2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    [redPoint2 lt_setLeft:X(41) to:redPoint1 save:YES];
    [redPoint2 lt_YcenterTo:redPoint1 save:YES];
    _limit = [[UILabel alloc]init];
    [contentBg addSubview:_limit];
    _limit.font = [UIFont fontWithName:@"DINAlternate-Bold" size:24];
    _limit.textColor = COLOR_TITLE_MAIN;
    [_limit lt_YcenterTo:_day save:YES];
    [_limit lt_leftEqual:redPoint2 save:YES];
    
    UIImageView *progressBg = [[UIImageView alloc]init];
    [progressBg setImage:[Sun imageWithColorFrom:COLOR_MAIN To:COLOR_MAIN Frame:CGRectMake(14, X(158), SCREENWIDTH - 28, 3) Direction:SunDirectionRight]];
    progressBg.userInteractionEnabled = YES;
    [contentBg addSubview:progressBg];
    [progressBg setFrame:CGRectMake(X(14), X(158), SCREENWIDTH - X(28), 3)];
    
    self.progress = [[UILabel alloc]init];
    [progressBg addSubview:self.progress];
    [self.progress setBackgroundColor:[UIColor colorWithHexString:@"F5F5F5"]];
    [self.progress setFrame:CGRectMake(0, 0, SCREENWIDTH - 28, 3)];
    
    self.progressLable = [[UILabel alloc]init];
    self.progressLable.backgroundColor = WHITE;
    [contentBg addSubview:self.progressLable];
    self.progressLable.textAlignment = NSTextAlignmentCenter;
    [self.progressLable setFrame:CGRectMake(X(14), X(153), 31, 14)];
    self.progressLable.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
    self.progressLable.textColor = COLOR_MAIN;
    self.progressLable.layer.cornerRadius = 7;
    self.progressLable.layer.masksToBounds = YES;
    self.progressLable.layer.borderColor = COLOR_MAIN.CGColor;
    self.progressLable.layer.borderWidth = 1;
    self.progressLable.text = @"20%";
    
    _startBtn = [[UIButton alloc]init];
    [contentBg addSubview:_startBtn];
    UILabel *btnTitle = [[UILabel alloc]init];
    [_startBtn addSubview:btnTitle];
    btnTitle.font = [UIFont fontWithName:@"PingFangSC-Medium" size:14];
    btnTitle.textColor = WHITE;
    btnTitle.text = @"立即投资";
    [btnTitle lt_XcenterTo:nil save:YES];
    [btnTitle lt_setTop:X(7) to:nil save:YES];
    [_startBtn setBackgroundImage:[UIImage imageNamed:@"first_btn"] forState:UIControlStateNormal];
    [_startBtn lt_setLeft:X(24) to:nil Right:X(25) to:nil save:YES];
    [_startBtn lt_setHeight:X(46) save:YES];
    [_startBtn lt_setTop:X(27) to:self.progress save:YES];
    [_startBtn addTarget:self action:@selector(gotoBuy) forControlEvents:UIControlEventTouchUpInside];
    [self updateViews];

}
- (void)setUpDataCell:(UITableViewCell *)cell{
#pragma mark- 平台数据
    UIView *dataBg = [[UIView alloc]init];
    [cell addSubview:dataBg];
    dataBg.backgroundColor = WHITE;
    [dataBg lt_Top:SunEdgesMake(0, 0, 0, X(130)) to:nil save:YES];
    UIImageView *safeImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"first_data_safe"]];
    [safeImage setFrame:CGRectMake(X(49), X(25), 59, 42)];
    [dataBg addSubview:safeImage];
    UIImageView *dealImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"first_data_deal"]];
    [dealImage setFrame:CGRectMake(X(182), X(25), 59, 42)];
    [dataBg addSubview:dealImage];
    UIImageView *earImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"first_data_ear"]];
    [earImage setFrame:CGRectMake(X(301), X(25), 59, 42)];
    [dataBg addSubview:earImage];
    
    self.dayLabel = [[UILabel alloc]initWithFrame:CGRectMake(X(36), X(32), 100, 24)];
    [dataBg addSubview:self.dayLabel];
    self.dayLabel.font = [UIFont fontWithName:@"DINAlternate-Bold" size:20];
    self.dayLabel.textColor = COLOR_MAIN;
    //    [self.dayLabel setMarkup:[NSString stringWithFormat:@"<font size = \"24\">1022</font><font size = \"12\">天</font>"]];
    self.dealLabel = [[UILabel alloc]initWithFrame:CGRectMake(X(156), X(32), 100, 24)];
    [dataBg addSubview:self.dealLabel];
    self.dealLabel.font = [UIFont fontWithName:@"DINAlternate-Bold" size:20];
    self.dealLabel.textColor = COLOR_MAIN;
    self.earLabel = [[UILabel alloc]initWithFrame:CGRectMake(X(283), X(32), 100, 24)];
    [dataBg addSubview:self.earLabel];
    self.earLabel.font = [UIFont fontWithName:@"DINAlternate-Bold" size:20];
    self.earLabel.textColor = COLOR_MAIN;
    
    UILabel *safeWord = [[UILabel alloc]initWithFrame:CGRectMake(X(35), X(60), 100, 24)];
    [dataBg addSubview:safeWord];
    safeWord.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    safeWord.textColor = COLOR_TITLE_MAIN;
    safeWord.text = @"安全运营";
    UILabel *dealWord = [[UILabel alloc]initWithFrame:CGRectMake(X(167), X(60), 100, 24)];
    [dataBg addSubview:dealWord];
    dealWord.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    dealWord.textColor = COLOR_TITLE_MAIN;
    dealWord.text = @"累计成交";
    UILabel *earWord = [[UILabel alloc]initWithFrame:CGRectMake(X(290), X(60), 100, 24)];
    [dataBg addSubview:earWord];
    earWord.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    earWord.textColor = COLOR_TITLE_MAIN;
    earWord.text = @"累计收益";
    UIView *bottom = [[UIView alloc]init];
    [dataBg addSubview:bottom];
    UIImageView *safe = [[UIImageView alloc]init];
    [bottom addSubview:safe];
    safe.image = [UIImage imageNamed:@"first_safe"];
    [safe lt_YcenterTo:nil save:YES];
    _safeLabel = [[UILabel alloc]init];
    [bottom addSubview:_safeLabel];
    _safeLabel.font = [UIFont systemFontOfSize:10];
    _safeLabel.textColor = COLOR_TITLE_MINOR;
    [_safeLabel lt_YcenterTo:nil save:YES];
    [_safeLabel lt_setLeft:X(5) to:safe save:YES];
    [bottom lt_layoutView:bottom side:SunLeft to:safe toSide:SunLeft withSize:1 offset:0 save:NO];
    [bottom lt_layoutView:bottom side:SunRight to:_safeLabel toSide:SunRight withSize:1 offset:0 save:YES];
    [bottom lt_XcenterTo:nil save:NO];
    [bottom lt_layoutView:bottom side:SunTop to:dealWord toSide:SunBottom withSize:1 offset:X(18) save:NO];
    _safeLabel.text = [self.homeDic objectForKey:@"safeText"];
    [self.dayLabel setMarkup:[NSString stringWithFormat:@"<font size = \"20\">%@</font><font size = \"12\">天</font>",[self.homeDic objectForKey:@"safeDay"]]];
    [self.dealLabel setMarkup:[NSString stringWithFormat:@"<font size = \"20\">%ld</font><font size = \"12\">万</font>",[[self.homeDic objectForKey:@"total"] integerValue]/10000 ]];
    [self.earLabel setMarkup:[NSString stringWithFormat:@"<font size = \"20\">%ld</font><font size = \"12\">万</font>",[[self.homeDic objectForKey:@"totalProfit"] integerValue]/10000 ]];

}
- (void)setUpCell:(UITableViewCell *)cell{
    cell.backgroundColor = [UIColor colorWithHexString:@"F9F9F9"];
#pragma mark- 活动banner
    _banner = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"first_banner"]];
    [cell addSubview:_banner];
    _banner.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    _banner.delegate = self;
    _banner.pageControlDotSize = CGSizeMake(X(15), X(4));
    _banner.currentPageDotColor = [UIColor colorWithHexString:@"FFD75E"];
    _banner.pageDotColor = COLOR_ALERT_BG;
    _banner.autoScrollTimeInterval = 3;
    [_banner lt_Top:SunEdgesMake(20, 0, 0, X(200)) to:nil save:YES];
#pragma mark- 新闻
    UIView *newsBg = [[UIView alloc]init];
    [cell addSubview:newsBg];
    newsBg.backgroundColor = [UIColor colorWithHexString:@"F9F9F9"];
    [newsBg lt_Top:SunEdgesMake(0, 0, 0, X(29)) to:_banner save:YES];
    UIImageView *newsImg = [[UIImageView alloc]init];
    [newsBg addSubview:newsImg];
    newsImg.image = [UIImage imageNamed:@"first_company"];
    [newsImg lt_Left:SunEdgesMake(X(7), X(12), X(7), -1) to:nil save:YES];
    _news = [[SDCycleScrollView alloc]init];
    [newsBg addSubview:_news];
    _news.delegate = self;
    _news.autoScrollTimeInterval = 3;
    _news.onlyDisplayText = YES;
    _news.titleLabelBackgroundColor = [UIColor clearColor];
    _news.titleLabelTextColor = COLOR_TITLE_MAIN;
    _news.titleLabelTextFont = FONT_TITLE_FOUR;
    _news.scrollDirection = UICollectionViewScrollDirectionVertical;
    _news.titlesGroup = @[@"正在连接网络，请稍候。。。"];
    [_news lt_setTop:0 to:nil Bottom:0 to:nil save:YES];
    [_news lt_setLeft:X(0) to:newsImg Right:X(50) to:nil save:YES];
    
    UIButton *moreBtn = [[UIButton alloc]init];
    [moreBtn addTarget:self action:@selector(moreNewsAction) forControlEvents:UIControlEventTouchUpInside];
    [moreBtn setFrame:CGRectMake(SCREENWIDTH - X(50), 0, X(50), X(24))];
    [newsBg addSubview:moreBtn];
    UILabel *moreLabel = [[UILabel alloc]init];
    [moreBtn addSubview:moreLabel];
    moreLabel.font = FONT_TITLE_FOUR;
    moreLabel.textColor = COLOR_TITLE_MINOR;
    moreLabel.text = @"更多";
    [moreLabel lt_setTop:0 to:nil Bottom:0 to:nil save:YES];
    [moreLabel lt_setRight:X(15) to:nil save:YES];
    UIImageView *moreNew = [[UIImageView alloc]init];
    [moreBtn addSubview:moreNew];
    [moreNew setImage:[UIImage imageNamed:@"first_next"]];
    [moreNew lt_setSize:CGSizeMake(X(5), X(10)) save:YES];
    [moreNew lt_YcenterTo:nil save:YES];
    [moreNew lt_setRight:X(6) to:nil save:YES];
    
    NSMutableArray *arr = [NSMutableArray array];
    for (int i=0; i<_bannerArr.count; i++) {
        [arr addObject:[NSString stringWithFormat:@"%@%@",KIMG,[_bannerArr[i] objectForKey:@"img"]]];
    }
    _banner.imageURLStringsGroup = arr;
    //news
    arr = [NSMutableArray array];
    for (int i=0; i<_newsArr.count; i++) {
        NSString *title = [_newsArr[i] objectForKey:@"title"];
        NSString *time = [Sun timestamp:[[_newsArr[i] objectForKey:@"time"] longLongValue] ToTime:@"YYYY-MM-dd"];
        [arr addObject:[NSString stringWithFormat:@"%@  %@",title,time]];
    }
    _news.titlesGroup = arr;
}
- (void)moreNewsAction {
    SunWebVC *vc = [[SunWebVC alloc]init];
    vc.urlStr = [NSString stringWithFormat:@"%@%@",KWAP,@"/More/getArticleByNid?nid=notice&type=1&source=ios"];
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)creatUI{
    _tb = [[UITableView alloc]initWithFrame:CGRectMake(0, -20, SCREENWIDTH, SCREENHEIGHT - 49 + 20) style:UITableViewStylePlain];
    [self.view addSubview:_tb];
    _tb.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestURL)];
    _tb.delegate = self;
    _tb.dataSource = self;
    _tb.showsVerticalScrollIndicator = NO;
    _tb.backgroundColor = [UIColor colorWithHexString:@"F9F9F9"];
    [self creatFloat];
}

- (void)creatFloat{
    _flaot = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, X(50), X(50))];
    _flaot.hidden = YES;
//    [_flaot setImage:[UIImage imageNamed:@"first_help"] forState:UIControlStateNormal];
    [_flaot sd_setBackgroundImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[self.floatDic objectForKey:@"img"]]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"first_help"]];
    [self.view addSubview:_flaot];
    [_flaot addTarget:self action:@selector(help) forControlEvents:UIControlEventTouchUpInside];
    _flaot.center = CGPointMake(X(320), Y(320));
    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestures:)];
    panGestureRecognizer.minimumNumberOfTouches = 1;
    panGestureRecognizer.maximumNumberOfTouches = 1;
    [_flaot addGestureRecognizer:panGestureRecognizer];
}

- (void)handlePanGestures:(UIPanGestureRecognizer*)recognizer{
    
    CGPoint translation = [recognizer translationInView:self.view];
    CGPoint newCenter = CGPointMake(recognizer.view.center.x+ translation.x,
                                    recognizer.view.center.y + translation.y);
    newCenter.y = MAX(recognizer.view.frame.size.height/2, newCenter.y);
    newCenter.y = MIN(self.view.frame.size.height - recognizer.view.frame.size.height/2-Y(40),  newCenter.y);
    newCenter.x = MAX(recognizer.view.frame.size.width/2, newCenter.x);
    newCenter.x = MIN(self.view.frame.size.width - recognizer.view.frame.size.width/2,newCenter.x);
    recognizer.view.center = newCenter;
    [recognizer setTranslation:CGPointZero inView:self.view];

}

#pragma mark new guy
- (void)help{
    SunWebVC *vc = [[SunWebVC alloc]init];
    NSString *str = @"CZfSDQzsuDayjfzE";
    NSString *str1 =@"12345678";
    NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
    NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
    vc.urlStr = [NSString stringWithFormat:@"%@?source=ios&token_id=%@&sign=%@",[self.floatDic objectForKey:@"param"],token_id,md5Str];
    [self.navigationController pushViewController:vc animated:YES];
//    if (!_helpView) {
//        _helpView = [[UIImageView alloc]init];
//        _helpView.userInteractionEnabled = YES;
//        _helpView.image = [UIImage imageNamed:@"first_bg"];
//        UIButton *btn1 = [[UIButton alloc]init];
//        [_helpView addSubview:btn1];
//        [btn1 lt_setTop:0 to:nil save:YES];
//        [btn1 lt_setLeft:0 to:nil save:YES];
//        [btn1 lt_setSize:CGSizeMake(X(44), Y(44)) save:YES];
//        [btn1 setImage:[UIImage imageNamed:@"first_close"] forState:UIControlStateNormal];
//        [btn1 doclick:^{
//            [_sun hideShow];
//        }];
//        UIButton *btn2 = [[UIButton alloc]init];
//        [_helpView addSubview:btn2];
//        [btn2 lt_setLeft:X(20) to:nil save:YES];
//        [btn2 lt_setBottom:Y(40) to:nil save:YES];
//        [btn2 lt_setSize:CGSizeMake(X(115), Y(36)) save:YES];
//        [btn2 setImage:[UIImage imageNamed:@"first_btn1"] forState:UIControlStateNormal];
//        [btn2 addTarget:self action:@selector(safe) forControlEvents:UIControlEventTouchUpInside];
//        UIButton *btn3 = [[UIButton alloc]init];
//        [_helpView addSubview:btn3];
//        [btn3 lt_setRight:X(20) to:nil save:YES];
//        [btn3 lt_setBottom:Y(40) to:nil save:YES];
//        [btn3 lt_setSize:CGSizeMake(X(115), Y(36)) save:YES];
//        [btn3 setImage:[UIImage imageNamed:@"first_btn2"] forState:UIControlStateNormal];
//        [btn3 addTarget:self action:@selector(problem) forControlEvents:UIControlEventTouchUpInside];
//    }
//    [_sun show:_helpView to:self shouldReturn:NO];
//    [_helpView lt_setSize:CGSizeMake(X(280), Y(300)) save:YES];
//    [_helpView lt_XYcenterTo:nil save:YES];
}

- (void)safe{
    SunWebVC *vc = [[SunWebVC alloc]init];
    vc.urlStr = [NSString stringWithFormat:@"%@%@",KWAP,@"/guide_about.html?source=ios"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)problem{
    SunWebVC *vc = [[SunWebVC alloc]init];
    vc.urlStr = [NSString stringWithFormat:@"%@%@",KWAP,@"/guide_help.html?nid=help_about&source=ios"];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ---

- (void)requestURL{
    [self requestToHome];
    [self requestToRecommand];
    [self requestToDraw];
    [self requsetIcons];
    [self requsetInformation];
}

- (void)gotoBuy{
    SunProductDetailVC *vc = [[SunProductDetailVC alloc]init];
    vc.borrowId = [_details objectForKey:@"borrowId"];
    vc.title = _title.text;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if (cycleScrollView == _banner) {
        NSDictionary *data = _bannerArr[index];
        [SunSupport shouldPushController:data];
    }
    if (cycleScrollView == _news) {
        SunWebVC *vc = [[SunWebVC alloc]init];
        vc.urlStr = [NSString stringWithFormat:@"%@%@&source=ios",KWAP,[_newsArr[index] objectForKey:@"param"]];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)updateViews{
    if (!_details) {
        return;
    }
    if ([[_details objectForKey:@"aprAdd"]doubleValue] > 0){
        [_percent setMarkup:[NSString stringWithFormat:@"<font size = \"42\">%@</font><font size = \"24\">%%+%.2f%%</font>",[_details objectForKey:@"aprBase"],[[_details objectForKey:@"aprAdd"]doubleValue]]];
    }else {
        [_percent setMarkup:[NSString stringWithFormat:@"<font size = \"42\">%@</font><font size = \"24\">%%</font>",[_details objectForKey:@"aprBase"]]];
    }
    [_day setMarkup:[NSString stringWithFormat:@"<font size = \"24\">%@</font><font size = \"9\">天</font>",[_details objectForKey:@"days"]]];
    self.progressLable.text = [NSString stringWithFormat:@"%.f%%",[[_details objectForKey:@"progress"] doubleValue]*100];
    CGFloat left =[[_details objectForKey:@"progress"] doubleValue] * (SCREENWIDTH - X(28));
    [self.progress setFrame:CGRectMake(left, 0, SCREENWIDTH - X(28) -left, 3)];
    if ([[_details objectForKey:@"progress"] doubleValue]>=0.95) {
        [self.progressLable setFrame:CGRectMake(SCREENWIDTH-31-X(14), X(153), 31, 14)];
    }else{
        [self.progressLable setFrame:CGRectMake(left, X(153), 31, 14)];
    }
    [_limit setMarkup:[NSString stringWithFormat:@"<font size = \"24\">%@</font><font size = \"9\">元</font>",[_details objectForKey:@"limitMoney"]]];
    _title.text = [NSString stringWithFormat:@"%@   %@",[_details objectForKey:@"bname"],[_details objectForKey:@"bnumber"]];
    if ([[_details objectForKey:@"bdesc"] length] >0) {
        _state.hidden = NO;
        _stateTitle.text = [_details objectForKey:@"bdesc"];
    }else {
        _state.hidden = YES;
    }

}

#pragma mark requests
- (void)requestToDraw{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_DRAWTYPE];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [Sun setUser:requestDic forKey:DRAWTYPE];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

- (void)requestToHome{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_HOME];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *param = @{@"idfa":[user objectForKey:@"ADID"]};
    [HttpRequest postURL:url withParam:param success:^(id requestDic, NSString *msg) {
        [_sun hideActivity];
        [_tb.mj_header endRefreshing];
        //banner
        _bannerArr = [requestDic objectForKey:@"banner"];
        _newsArr = [requestDic objectForKey:@"news"];
        if ([requestDic objectForKey:@"xuanfu"] != nil) {
            self.floatDic = [requestDic objectForKey:@"xuanfu"];
            [_flaot sd_setBackgroundImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[self.floatDic objectForKey:@"img"]]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"first_help"]];
            _flaot.hidden = NO;
        }
        //text
        self.homeDic = requestDic;
        [Sun setUser:[requestDic objectForKey:@"safeText"] forKey:SAFETEXT];
        [Sun setUser:[requestDic objectForKey:@"loginText"] forKey:LOGINTEXT];
        [_tb reloadData];
    } failure:^(NSString *errorInfo, int code) {
        [_tb.mj_header endRefreshing];
        [_sun hideActivity];
    }];
}
- (void)requsetIcons {
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_FOURICON];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [_sun hideActivity];
        // title image next
        NSLog(@"%@+++++%@",API_FOURICON,requestDic);

        self.iconsArr = [NSMutableArray arrayWithArray:[requestDic objectForKey:@"list"]];
        [_tb reloadData];

    } failure:^(NSString *errorInfo, int code) {
        [_sun hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}
- (void)requsetInformation {
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_INFOMATION];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [_sun hideActivity];

        self.infoArr = [requestDic objectForKey:@"list"];
        [_tb reloadData];
    } failure:^(NSString *errorInfo, int code) {
        [_sun hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}
- (void)requestToRecommand{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_RECOMMAND];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [_sun hideActivity];
        _details = [NSMutableDictionary dictionaryWithDictionary:requestDic];
        [_tb reloadData];
    } failure:^(NSString *errorInfo, int code) {
        [_sun hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}


- (void)requestToVersion{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_VERSION];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        UIView *view = [[UIView alloc]init];
        UIImageView *img1 = [[UIImageView alloc]init];
        [view addSubview:img1];
        [img1 lt_setSize:CGSizeMake(X(311), Y(164)) save:YES];
        [img1 lt_XcenterTo:nil save:YES];
        [img1 lt_setTop:0 to:nil save:YES];
        UILabel *l1 = [[UILabel alloc]init];
        [img1 addSubview:l1];
        l1.text = @"发现新版本";
        l1.font = [UIFont boldSystemFontOfSize:21];
        l1.textColor = BLUE;
        [l1 lt_layoutView:l1 side:SunCenterX to:nil toSide:SunCenterX withSize:1 offset:-X(20) save:YES];
        [l1 lt_setBottom:Y(10) to:nil save:YES];
        UILabel *l2 = [[UILabel alloc]init];
        [img1 addSubview:l2];
        [l2 lt_YcenterTo:l1 save:YES];
        [l2 lt_setSize:CGSizeMake(X(56), Y(24)) save:YES];
        [l2 lt_setLeft:X(4) to:l1 save:YES];
        l2.backgroundColor = BLUE;
        l2.layer.cornerRadius = Y(12);
        l2.textColor = WHITE;
        l2.font = [UIFont boldSystemFontOfSize:11];
        l2.text = [NSString stringWithFormat:@"V%@",[requestDic objectForKey:@"version"]];
        l2.clipsToBounds = YES;
        l2.textAlignment = NSTextAlignmentCenter;
        img1.image = [UIImage imageNamed:@"version_top"];
        _web = [[UIWebView alloc]init];
        [view addSubview:_web];
        _web.scrollView.showsVerticalScrollIndicator = NO;
        [_web lt_setWidth:X(311) save:YES];
        [_web lt_setHeight:Y(120) save:YES];
        [_web lt_setTop:0 to:img1 save:YES];
        [_web lt_XcenterTo:nil save:YES];
        _web.backgroundColor = WHITE;
        _web.delegate = self;
        NSString *str = [requestDic objectForKey:@"content"];
        str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
        [_web loadHTMLString:[NSString stringWithFormat:@"<div style='margin-left:auto;margin-right:auto;line-height:1.5;width:200px;color:#333333';font-size:16px;>%@</div>",str] baseURL:nil];
        UIImageView *img2 = [[UIImageView alloc]init];
        [view addSubview:img2];
        [img2 lt_setSize:CGSizeMake(X(311), Y(130)) save:YES];
        [img2 lt_XcenterTo:nil save:YES];
        [img2 lt_setTop:0 to:_web save:YES];
        img2.userInteractionEnabled = YES;
        img2.image = [UIImage imageNamed:@"version_bottom"];
        UIButton *btn = [[UIButton alloc]init];
        [img2 addSubview:btn];
        [btn setImage:[UIImage imageNamed:@"first_update"] forState:UIControlStateNormal];
        [btn doclick:^{
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:APPSTORE]];
        }];
        [btn lt_XcenterTo:nil save:YES];
        [btn lt_setBottom:Y(15) to:nil save:YES];
        UIButton *cancel = [[UIButton alloc]init];
        [view addSubview:cancel];
        [cancel lt_setTop:Y(10) to:img2 save:YES];
        if ([[requestDic objectForKey:@"must"]intValue] == 1) {
            [cancel lt_setSize:CGSizeMake(0, 0) save:YES];
        }else {
            [cancel lt_setSize:CGSizeMake(X(60), X(60)) save:YES];
            [cancel setImage:[UIImage imageNamed:@"tool_bigcancel"] forState:UIControlStateNormal];
        }
        [cancel lt_XcenterTo:nil save:YES];
        [cancel doclick:^{
            [[Sun shareSun]hideShow];
            [self showActivity];
        }];
        [[Sun shareSun]show:view to:[UIApplication sharedApplication].keyWindow shouldReturn:NO];
        [view lt_XYcenterTo:nil save:YES];
        [view lt_topEqual:img1 save:YES];
        [view lt_bottomEqual:cancel save:YES];
        [view lt_setWidth:X(311) save:YES];
    } failure:^(NSString *errorInfo, int code) {
        [self showActivity];
    }];
}

- (void)showActivity{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_ALERT];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        _adsData = requestDic;
        UIView *view = [[UIView alloc]init];
        UIImageView *img = [[UIImageView alloc]init];
        img.contentMode = UIViewContentModeScaleAspectFit;
        img.image = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[requestDic objectForKey:@"img"]]]]];
        img.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(adsTap)];
        [img addGestureRecognizer:tap];
        [view addSubview:img];
        [img lt_XcenterTo:nil save:YES];
        [img lt_setWidth:X(320) save:YES];
        [img lt_heightRelyWidth:(img.image.size.height / img.image.size.width) save:YES];
        UIButton *btn = [[UIButton alloc]init];
        [view addSubview:btn];
        [btn lt_setTop:Y(10) to:img save:YES];
        [btn lt_setSize:CGSizeMake(X(60), X(60)) save:YES];
        [btn lt_XcenterTo:nil save:YES];
        [btn setImage:[UIImage imageNamed:@"tool_bigcancel"] forState:UIControlStateNormal];
        [btn doclick:^{
            [[Sun shareSun]hideShow];
        }];
        [[Sun shareSun]show:view to:[UIApplication sharedApplication].keyWindow shouldReturn:NO];
        [view lt_XYcenterTo:nil save:YES];
        [view lt_topEqual:img save:YES];
        [view lt_leftEqual:img save:YES];
        [view lt_rightEqual:img save:YES];
        [view lt_bottomEqual:btn save:YES];
    } failure:^(NSString *errorInfo, int code) {
        
    }];
}

- (void)showRegister{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_REG];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        _adsData = requestDic;
        UIView *view = [[UIView alloc]init];
        UIImageView *img = [[UIImageView alloc]init];
        img.contentMode = UIViewContentModeScaleAspectFit;
        img.image = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[requestDic objectForKey:@"img"]]]]];
        img.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(adsTap)];
        [img addGestureRecognizer:tap];
        [view addSubview:img];
        [img lt_XcenterTo:nil save:YES];
        [img lt_setWidth:X(320) save:YES];
        if (img.image.size.height == 0) {
            [img lt_setHeight:X(320) save:YES];
        }else{
            [img lt_heightRelyWidth:(img.image.size.height / img.image.size.width) save:YES];
        }
        UIButton *btn = [[UIButton alloc]init];
        [view addSubview:btn];
        [btn lt_setTop:Y(10) to:img save:YES];
        [btn lt_setSize:CGSizeMake(X(60), X(60)) save:YES];
        [btn lt_XcenterTo:nil save:YES];
        [btn setImage:[UIImage imageNamed:@"tool_bigcancel"] forState:UIControlStateNormal];
        [btn doclick:^{
            [[Sun shareSun]hideShow];
            [self requestToVersion];
        }];
        [[Sun shareSun]show:view to:[UIApplication sharedApplication].keyWindow shouldReturn:NO];
        [view lt_XYcenterTo:nil save:YES];
        [view lt_topEqual:img save:YES];
        [view lt_leftEqual:img save:YES];
        [view lt_rightEqual:img save:YES];
        [view lt_bottomEqual:btn save:YES];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

- (void)adsTap{
    [[Sun shareSun]hideShow];
    [SunSupport shouldPushController:_adsData];
}

#pragma mark tableView
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section>1) {
        return X(8);
    }
    return 0.01;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.infoArr == NULL || self.infoArr.count < 1) {
        return 4;
    }else{
        return 5;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return X(247);
            break;
        case 1:{
            if (self.iconsArr == NULL || self.iconsArr.count== 0) {
                return X(74);
            }else{
                NSInteger i = self.iconsArr.count%4 == 0?0:1;
                return X(74)*(self.iconsArr.count/4+i);
            }
        }
            break;
        case 2:
            return X(282);
            break;
        case 3:{
            if (self.infoArr == NULL || self.infoArr.count < 1) {
                return X(130);
            }else{
                if (self.infoArr.count == 1) {
                    return X(144);
                }else if (self.infoArr.count>=2){
                    return X(250);
                }
            }
        }
            break;
        case 4:
            return X(130);
            break;
        default:
            break;
    }
    return X(948);
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:{
            UITableViewCell *cell = [[UITableViewCell alloc]init];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [self setUpCell:cell];
            return cell;
        }
            break;
        case 1:{
            UITableViewCell *cell = [[UITableViewCell alloc]init];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [self setUpIconCell:cell];
            return cell;
        }
            break;
        case 2:{
            UITableViewCell *cell = [[UITableViewCell alloc]init];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [self setUpProductCell:cell];
            return cell;
        }
            
            break;
        case 3:{
            if (self.infoArr == NULL || self.infoArr.count < 1) {
                UITableViewCell *cell = [[UITableViewCell alloc]init];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                [self setUpDataCell:cell];
                return cell;
            }else{
                UITableViewCell *cell = [[UITableViewCell alloc]init];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                [self setUpInforCell:cell];
                return cell;
            }
        }
        case 4:{
            UITableViewCell *cell = [[UITableViewCell alloc]init];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [self setUpDataCell:cell];
            return cell;
        }
            
            break;
        default:
            break;
    }
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 2) {
        [self gotoBuy];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
